```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java GC Roots 机制详解 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
            background-color: #f8f9fa;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: #2c3e50;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
        }
        .code-block {
            background-color: #282c34;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background-color: #21252b;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            padding: 8px 15px;
            color: #9da5b4;
            font-size: 0.9rem;
            display: flex;
            justify-content: space-between;
        }
        .code-copy {
            cursor: pointer;
            transition: color 0.2s;
        }
        .code-copy:hover {
            color: #61afef;
        }
        pre {
            margin: 0;
            padding: 15px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            color: #abb2bf;
            font-size: 0.9rem;
        }
        .mermaid {
            background-color: #fff;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .section-divider {
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(0,0,0,0.1), transparent);
            margin: 40px 0;
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(110, 142, 251, 0.2);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover::after {
            height: 50%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <header class="hero-gradient text-white py-20 px-4 sm:px-6 lg:px-8">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6 animate-fade-in-down">Java GC Roots 机制解析</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8 max-w-3xl mx-auto">
                探索垃圾回收器如何通过 GC Roots 确定对象的可达性
            </p>
            <div class="flex justify-center space-x-4">
                <a href="#content" class="bg-white text-indigo-600 px-6 py-3 rounded-full font-medium hover:bg-gray-100 transition duration-300 shadow-md">
                    <i class="fas fa-book-open mr-2"></i>开始阅读
                </a>
                <a href="#visualization" class="bg-white bg-opacity-20 px-6 py-3 rounded-full font-medium hover:bg-opacity-30 transition duration-300 shadow-md">
                    <i class="fas fa-project-diagram mr-2"></i>可视化图表
                </a>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 py-12">
        <article class="prose prose-lg max-w-none">
            <!-- Introduction -->
            <section id="content" class="mb-16">
                <div class="bg-white rounded-xl shadow-md p-6 md:p-8 mb-8 card-hover">
                    <p class="text-xl text-gray-700 leading-relaxed">
                        在 Java 的垃圾回收（GC）机制中，GC Roots 是一组对象的集合，垃圾回收器通过这些对象来确定哪些对象是"可达"的。任何从这些 GC Roots 可达的对象都会被认为是活动的，不会被垃圾回收。GC Roots 是垃圾回收器在进行垃圾回收时用来进行对象可达性分析的起点。
                    </p>
                </div>
                
                <div class="mb-12 text-center">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1660454426266-9e7c5c02-7a80-4ed0-a57f-e37e62101c0d.png" 
                         alt="GC Roots示意图" 
                         class="rounded-lg shadow-xl mx-auto max-w-full h-auto">
                    <p class="text-gray-500 text-sm mt-2">GC Roots 可达性分析示意图</p>
                </div>
            </section>

            <!-- 7 Types of GC Roots -->
            <section class="mb-16">
                <h2 class="text-3xl font-bold mb-8 text-center">七种主要的 GC Roots 类型</h2>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <!-- 1. 虚拟机栈中的引用 -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                        <div class="bg-indigo-100 p-4">
                            <h3 class="text-xl font-semibold text-indigo-800 flex items-center">
                                <span class="bg-indigo-600 text-white w-8 h-8 rounded-full flex items-center justify-center mr-3">1</span>
                                虚拟机栈中的引用
                            </h3>
                        </div>
                        <div class="p-6">
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-indigo-500 mt-2 mr-2"></i>
                                    <span><strong>栈帧中的局部变量</strong>：当前线程的栈帧中的局部变量表中存储的对象引用。这些对象是当前方法调用中的活动对象。</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-indigo-500 mt-2 mr-2"></i>
                                    <span><strong>栈中的引用</strong>：活跃的线程栈帧中的对象引用，包括方法调用的参数和局部变量。</span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <!-- 2. 方法区中的引用 -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                        <div class="bg-purple-100 p-4">
                            <h3 class="text-xl font-semibold text-purple-800 flex items-center">
                                <span class="bg-purple-600 text-white w-8 h-8 rounded-full flex items-center justify-center mr-3">2</span>
                                方法区中的引用
                            </h3>
                        </div>
                        <div class="p-6">
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-2 mr-2"></i>
                                    <span><strong>常量池中的引用</strong>：在方法区中，常量池存储了类、方法和字段等的常量信息。常量池中的对象引用也是 GC Roots 的一部分。</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-purple-500 mt-2 mr-2"></i>
                                    <span><strong>静态字段</strong>：类的静态字段持有的对象引用，因为它们在整个应用程序的生命周期内都存在。</span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <!-- 3. 类加载器 -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                        <div class="bg-blue-100 p-4">
                            <h3 class="text-xl font-semibold text-blue-800 flex items-center">
                                <span class="bg-blue-600 text-white w-8 h-8 rounded-full flex items-center justify-center mr-3">3</span>
                                类加载器
                            </h3>
                        </div>
                        <div class="p-6">
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-blue-500 mt-2 mr-2"></i>
                                    <span><strong>类的引用</strong>：被加载的类的 Class 对象也是 GC Roots。因为这些 Class 对象由类加载器持有，所以它们的引用也是 GC Roots。</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-blue-500 mt-2 mr-2"></i>
                                    <span><strong>类加载器本身</strong>：类加载器对象引用的 Class 对象，通常这些对象是在方法区中存在的。</span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <!-- 4. 线程 -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                        <div class="bg-green-100 p-4">
                            <h3 class="text-xl font-semibold text-green-800 flex items-center">
                                <span class="bg-green-600 text-white w-8 h-8 rounded-full flex items-center justify-center mr-3">4</span>
                                线程
                            </h3>
                        </div>
                        <div class="p-6">
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-green-500 mt-2 mr-2"></i>
                                    <span><strong>活动线程</strong>：当前正在运行的线程和它们持有的对象引用，包括线程的栈、锁和其他线程状态信息。</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-green-500 mt-2 mr-2"></i>
                                    <span><strong>ThreadLocal 变量</strong>：被线程持有的 ThreadLocal 对象及其关联的值也是 GC Roots。</span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <!-- 5. JNI 引用 -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                        <div class="bg-yellow-100 p-4">
                            <h3 class="text-xl font-semibold text-yellow-800 flex items-center">
                                <span class="bg-yellow-600 text-white w-8 h-8 rounded-full flex items-center justify-center mr-3">5</span>
                                JNI 引用
                            </h3>
                        </div>
                        <div class="p-6">
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-yellow-500 mt-2 mr-2"></i>
                                    <span><strong>Native 代码中的引用</strong>：通过 JNI (Java Native Interface) 直接持有的对象引用。这些引用可能来自于 C/C++ 代码中对 Java 对象的持有。</span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <!-- 6. 其他系统资源 -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                        <div class="bg-red-100 p-4">
                            <h3 class="text-xl font-semibold text-red-800 flex items-center">
                                <span class="bg-red-600 text-white w-8 h-8 rounded-full flex items-center justify-center mr-3">6</span>
                                其他系统资源
                            </h3>
                        </div>
                        <div class="p-6">
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-red-500 mt-2 mr-2"></i>
                                    <span><strong>系统资源</strong>：如打开的文件描述符、网络连接等，它们通常不直接属于 GC Roots，但在某些实现中可能被包括在 GC Roots 的范围内。</span>
                                </li>
                            </ul>
                        </div>
                    </div>

                    <!-- 7. ThreadGroup 和 System ClassLoader -->
                    <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                        <div class="bg-pink-100 p-4">
                            <h3 class="text-xl font-semibold text-pink-800 flex items-center">
                                <span class="bg-pink-600 text-white w-8 h-8 rounded-full flex items-center justify-center mr-3">7</span>
                                ThreadGroup 和 System ClassLoader
                            </h3>
                        </div>
                        <div class="p-6">
                            <ul class="space-y-3">
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-pink-500 mt-2 mr-2"></i>
                                    <span><strong>ThreadGroup</strong>：当前线程所属的 ThreadGroup 对象。</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-circle text-xs text-pink-500 mt-2 mr-2"></i>
                                    <span><strong>System ClassLoader</strong>：系统类加载器（bootstrap class loader）及其所持有的对象引用。</span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Example Section -->
            <section id="example" class="mb-16">
                <h2 class="text-3xl font-bold mb-6">代码示例</h2>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover mb-8">
                    <div class="p-6">
                        <p class="text-gray-700 mb-6">
                            假设我们有一个简单的 Java 应用，创建了一些对象，并进行了方法调用：
                        </p>
                        
                        <div class="code-block">
                            <div class="code-header">
                                <span>GCRootsDemo.java</span>
                                <button class="code-copy"><i class="far fa-copy"></i> 复制</button>
                            </div>
                            <pre><code>public class GCRootsDemo {
    public static void main(String[] args) {
        GCRootsDemo demo = new GCRootsDemo();
        demo.createObject();
        
        // 触发垃圾回收
        System.gc();
    }
    
    public void createObject() {
        Object obj = new Object(); // obj 是 GC Roots 的一个引用
    }
}</code></pre>
                        </div>
                        
                        <div class="mt-6 text-gray-700">
                            <p class="mb-4">在上述代码中：</p>
                            <ul class="space-y-2">
                                <li class="flex items-start">
                                    <i class="fas fa-chevron-right text-xs text-indigo-500 mt-1 mr-2"></i>
                                    <span><code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">demo</code> 是 <code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">main</code> 方法的局部变量（栈中的引用）。</span>
                                </li>
                                <li class="flex items-start">
                                    <i class="fas fa-chevron-right text-xs text-indigo-500 mt-1 mr-2"></i>
                                    <span><code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">obj</code> 是 <code class="bg-indigo-100 text-indigo-800 px-2 py-1 rounded">createObject</code> 方法的局部变量（栈中的引用）。</span>
                                </li>
                            </ul>
                            <p class="mt-4">
                                当垃圾回收器进行可达性分析时，它会从这些 GC Roots 开始，确定哪些对象是可达的，从而决定哪些对象可以被回收，哪些对象应该保留。
                            </p>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Visualization Section -->
            <section id="visualization" class="mb-16">
                <h2 class="text-3xl font-bold mb-8 text-center">GC Roots 可视化分析</h2>
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="mermaid">
                        graph TD
                            A[GC Roots] --> B[虚拟机栈中的引用]
                            A --> C[方法区中的引用]
                            A --> D[类加载器]
                            A --> E[线程]
                            A --> F[JNI 引用]
                            A --> G[其他系统资源]
                            A --> H[ThreadGroup 和 System ClassLoader]
                            
                            B --> B1[栈帧中的局部变量]
                            B --> B2[栈中的引用]
                            
                            C --> C1[常量池中的引用]
                            C --> C2[静态字段]
                            
                            D --> D1[类的引用]
                            D --> D2[类加载器本身]
                            
                            E --> E1[活动线程]
                            E --> E2[ThreadLocal 变量]
                            
                            F --> F1[Native 代码中的引用]
                            
                            G --> G1[打开的文件描述符]
                            G --> G2[网络连接]
                            
                            H --> H1[ThreadGroup]
                            H --> H2[System ClassLoader]
                    </div>
                </div>
            </section>

            <!-- Key Takeaways -->
            <section class="bg-indigo-50 rounded-xl p-8 mb-16">
                <h2 class="text-2xl font-bold text-indigo-800 mb-6 flex items-center">
                    <i class="fas fa-lightbulb text-indigo-600 mr-3"></i>
                    关键要点总结
                </h2>
                <ul class="space-y-4">
                    <li class="flex items-start">
                        <div class="flex-shrink-0 bg-indigo-100 p-2 rounded-full mr-3">
                            <i class="fas fa-check text-indigo-600"></i>
                        </div>
                        <span class="text-gray-700">GC Roots 是垃圾回收器进行可达性分析的起点，所有从 GC Roots 可达的对象都是活动对象，不会被回收</span>
                    </li>
                    <li class="flex items-start">
                        <div class="flex-shrink-0 bg-indigo-100 p-2 rounded-full mr-3">
                            <i class="fas fa-check text-indigo-600"></i>
                        </div>
                        <span class="text-gray-700">主要 GC Roots 包括虚拟机栈中的引用、方法区中的引用、类加载器、线程、JNI 引用等</span>
                    </li>
                    <li class="flex items-start">
                        <div class="flex-shrink-0 bg-indigo-100 p-2 rounded-full mr-3">
                            <i class="fas fa-check text-indigo-600"></i>
                        </div>
                        <span class="text-gray-700">理解 GC Roots 有助于优化内存使用，避免内存泄漏</span>
                    </li>
                    <li class="flex items-start">
                        <div class="flex-shrink-0 bg-indigo-100 p-2 rounded-full mr-3">
                            <i class="fas fa-check text-indigo-600"></i>
                        </div>
                        <span class="text-gray-700">不同的 GC 算法对 GC Roots 的处理方式可能有所不同</span>
                    </li>
                </ul>
            </section>
        </article>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex flex-col items-center">
                <div class="text-xl font-semibold text-white mb-4">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="text-indigo-400 hover:text-indigo-300 transition duration-300">
                    <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                </a>
                <div class="mt-6 flex space-x-6">
                    <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fab fa-github text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fab fa-twitter text-xl"></i>
                    </a>
                    <a href="#" class="text-gray-400 hover:text-white transition duration-300">
                        <i class="fab fa-linkedin text-xl"></i>
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });

        // Copy code functionality
        document.querySelectorAll('.code-copy').forEach(button => {
            button.addEventListener('click', () => {
                const codeBlock = button.parentElement.parentElement.querySelector('code');
                const codeText = codeBlock.textContent;
                
                navigator.clipboard.writeText(codeText).then(() => {
                    button.innerHTML = '<i class="fas fa-check"></i> 已复制';
                    setTimeout(() => {
                        button.innerHTML = '<i class="far fa-copy"></i> 复制';
                    }, 2000);
                });
            });
        });

        // Smooth scrolling for anchor links
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                
                const targetId = this.getAttribute('href');
                if (targetId === '#') return;
                
                const targetElement = document.querySelector(targetId);
                if (targetElement) {
                    window.scrollTo({
                        top: targetElement.offsetTop - 80,
                        behavior: 'smooth'
                    });
                }
            });
        });
    </script>
</body>
</html>
```